package com.wzy.authority.base.result;

import lombok.Data;

import java.io.Serializable;
import java.util.List;

/**
 * @program: authorityManagement
 * @description: 返回结果集
 * @author: 1
 * @create: 2020-03-14 11:51
 **/


@Data
public class Results<T> implements Serializable {

    private static final long serialVersionUID = -495606212385648827L;
    /**
     * 数据数量
     */
    private Long count;
    /**
     * 代码
     */
    private Integer code;
    /**
     * 消息
     */
    private String msg;
    /**
     * 任何类型条件
     */
    private transient T data;

    public Results() {
    }

    public Results(Integer code, String msg) {
        super();
        this.code = code;
        this.msg = msg;
    }

    public Results(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public Results(Integer code, String msg, T data, Long count) {
        this.code = code;
        this.msg = msg;
        this.data = data;
        this.count = count;
    }


    /**
     * 无数据传输的 成功返回
     */
    public static <T> Results<T> success() {
        return new Results<>(ResponseCode.SUCCESS.getCode(), ResponseCode.SUCCESS.getMessage());
    }

    public static <T> Results<T> success(String msg) {
        return new Results<>(ResponseCode.SUCCESS.getCode(), msg);
    }

    public static <T> Results<T> success(ResponseCode resultCode) {
        return new Results<>(resultCode.getCode(), resultCode.getMessage());
    }

    /**
     * 单个数据传输的 成功返回
     *
     * @param data
     * @param <T>
     * @return
     */
    public static <T> Results<T> success(T data,Long count) {
        return new Results<>(ResponseCode.SUCCESS.getCode(), ResponseCode.SUCCESS.getMessage(), data, count);
    }

    public static <T> Results<T> success(String msg, T data) {
        return new Results<>(ResponseCode.SUCCESS.getCode(), msg, data);
    }

    public static <T> Results<T> success(ResponseCode resultCode, T data) {
        return new Results<>(resultCode.getCode(), resultCode.getMessage(), data);
    }

    /**
     * 分页数据传输的 成功返回
     */
    public static <T> Results<T> success(Long count) {
        return new Results<>(ResponseCode.TABLE_SUCCESS.getCode(), ResponseCode.SUCCESS.getMessage(), null, count);
    }

    public static <T> Results<T> success(String msg, Long count) {
        return new Results<>(ResponseCode.TABLE_SUCCESS.getCode(), msg, null, count);
    }

    public static <T> Results<T> success(ResponseCode resultCode, Long count) {
        return new Results<>(resultCode.getCode(), resultCode.getMessage(), null, count);
    }

    /**
     * 无数据传输的 失败返回
     */
    public static <T> Results<T> failure() {
        return new Results<>(ResponseCode.FAIL.getCode(), ResponseCode.FAIL.getMessage());
    }

    public static <T> Results<T> failure(ResponseCode resultCode) {
        return new Results<>(resultCode.getCode(), resultCode.getMessage());
    }


    public static <T> Results<T> failure(String message) {
        return new Results<T>(ResponseCode.FAIL.getCode(), message);
    }

    public static <T> Results<T> failure(Integer code, String msg) {
        return new Results<>(code, msg);
    }

    public static Results ok() {
        return new Results();
    }
}
